package enumdemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-08-01
 * Time: 23:10
 */
public enum TestEnum {
    RED(0,"RED"),BLACK(1,"BLACK"),
    GREEN(2,"GREEN"),WHITE(3,"WHITE");

    public int ordinal;
    public String color;


    //构造方法默认私有
    TestEnum(int ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }

    public static void main(String[] args) {
        TestEnum[] testEnums1 = TestEnum.values();
        for (int i = 0; i < testEnums1.length; i++) {
            System.out.println(testEnums1[i] +" "+ testEnums1[i].ordinal());
        }

        TestEnum testEnum = TestEnum.valueOf("GREEN");
        System.out.println(testEnum);
    }

    public static void main1(String[] args) {

        TestEnum testEnum = TestEnum.BLACK;

        switch (testEnum) {
            case RED -> {
                System.out.println(RED);
                break;
            }

            case BLACK -> {
                System.out.println(BLACK);
                break;
            }

            case GREEN -> {
                System.out.println(GREEN);
                break;
            }

            case WHITE -> {
                System.out.println(WHITE);
                break;
            }
        }


    }

}
